d2e294
@@ -11620,6 +11620,14 @@
ASTNode analyzeCreateTable(
       }
     }
 
+    if (command_type == CREATE_TABLE || command_type == CTLT) {
+        queryState.setCommandType(HiveOperation.CREATETABLE);
+    } else if (command_type == CTAS) {
+        queryState.setCommandType(HiveOperation.CREATETABLE_AS_SELECT);
+    } else {
+        throw new SemanticException("Unrecognized command.");
+    }
+
     storageFormat.fillDefaultStorageFormat(isExt);
 
     if ((command_type == CTAS) && (storageFormat.getStorageHandler() != null)) {
@@ -11681,7 +11689,6 @@
ASTNode analyzeCreateTable(
       crtTblDesc.validate(conf);
       // outputs is empty, which means this create table happens in the current
       // database.
-      queryState.setCommandType(HiveOperation.CREATETABLE);
       rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
           crtTblDesc), conf));
       break;
@@ -11700,7 +11707,6 @@
ASTNode analyzeCreateTable(
           storageFormat.getInputFormat(), storageFormat.getOutputFormat(), location,
           storageFormat.getSerde(), storageFormat.getSerdeProps(), tblProps, ifNotExists,
           likeTableName, isUserStorageFormat);
-      queryState.setCommandType(HiveOperation.CREATETABLE);
       rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
           crtTblLikeDesc), conf));
       break;
@@ -11774,8 +11780,6 @@
ASTNode analyzeCreateTable(
       tableDesc.setNullFormat(rowFormatParams.nullFormat);
       qb.setTableDesc(tableDesc);
 
-      queryState.setCommandType(HiveOperation.CREATETABLE_AS_SELECT);
-
       return selectStmt;
     default:
       throw new SemanticException("Unrecognized command.");
